package com.macasa.panel.entity.impl;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Version;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import com.google.common.base.Objects;
import com.macasa.panel.common.utils.CastHelpers;
import com.macasa.panel.entity.api.AbstractModel;
import com.macasa.panel.entity.api.ISGBDService;
import com.macasa.panel.entity.api.ISGBDServiceUser;

@Entity
@Table(name = "sgbd_service_user")
@SequenceGenerator(name = "SGBDServiceUser_SEQ", sequenceName = "SGBDServiceUserIdSeq", initialValue = 1)
@Getter
@Setter
@ToString
public class SGBDServiceUser extends AbstractModel<Integer> implements ISGBDServiceUser {

	/**
	 * The Constant serialVersionUID
	 */
	@Version
	private static final long	serialVersionUID	= 6597741403872678281L;

	@Id
	@Column(name = "sgbd_service_user_id", nullable = false)
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "SGBDServiceUser_SEQ")
	private Integer				id;

	@Column(name = "sgbd_user", nullable = false)
	private String				sgbdUser;

	@Column(name = "sgbd_password", nullable = false)
	private String				sgbdPassword;

	@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY, targetEntity = com.macasa.panel.entity.impl.SGBDService.class)
	@JoinColumn(name = "fk_sgbd_service_id", nullable = false)
	private ISGBDService		sgbdService;

	@Override
	public boolean equals(final Object obj) {

		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof SGBDServiceUser)) {
			return false;
		}

		final SGBDServiceUser other = CastHelpers.cast(obj, SGBDServiceUser.class);

		return Objects.equal(this.id, other.id) && Objects.equal(this.sgbdUser, other.sgbdUser) && Objects.equal(this.sgbdPassword, other.sgbdPassword)
				&& Objects.equal(this.sgbdService, other.sgbdService);
	}

	@Override
	public int hashCode() {
		return Objects.hashCode(this.id, this.sgbdUser, this.sgbdPassword, this.sgbdService);
	}
}
